<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>线下订单</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/my/offlineOrders/offlineOrders.css" />
    <style>

    </style>
</head>

<body>
    <div id="app" v-clock>
        <div class="aui-tab border_b" id="tab">
            <div class="aui-tab-item aui-active">收款订单</div>
            <div class="aui-tab-item">付款订单</div>
        </div>
        <div class="content" v-show="infoStatus">
            <div class="list_wrap aui-margin-b-10" v-for="o,i in list">
                <div class="padded_2 list">
                    <div class="gray_8 aui-font-size-12">订单号：{{o.order_no}}</div>
                    <div class="border_t">{{o.order_title}}</div>
                    <div class="flex-row">
                        <div class="pull-left aui-text-danger">￥{{o.order_price}}</div>
                        <div class="pull-right gray_8">下单时间：{{o.create_date}}</div>
                    </div>
                    <div class="border_t" v-if="listType==1">付款账号：{{o.drawee_account}}</div>
                    <div class="border_t" v-if="listType==2">收款账号：{{o.payee_account}}</div>
                    <div class="border_t gray_8">订单备注：{{o.order_notes}}</div>
                </div>
                <div class="order_status" v-if="listType==1">
                    <div class="status" v-if="o.order_status===0">已取消</div>
                    <div class="status" v-if="o.order_status===1">未支付</div>
                    <div class="status" v-if="o.order_status===2">已支付</div>
                </div>
                <div class="order_status" v-if="listType==2">
                    <div class="status" v-if="o.order_status===0">已取消</div>
                    <div class="btn" v-if="o.order_status===1" @click="cannel(o)">取消付款</div>
                    <div class="btn" v-if="o.order_status===1" @click="goPay(o)">去支付</div>
                    <div class="status" v-if="o.order_status===2">已支付</div>
                </div>
            </div>

        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            infoStatus: true,
            userInfo: {},

            list: [],
            listType: 1,
            listPage: 1,
            listStatus: true,
        },
        methods: {
            init() {
                var that = this;
                this.userInfo = get_local("userInfo");
                this.upDownLoad();
                this.tabChange();
                this.getList();

                api.addEventListener({
                    name: 'add_offlineOrders'
                }, function(ret, err) {
                    that.listStatus = true;
                    that.listPage = 1;
                    that.list = [];
                    that.getList();
                });
            },
            getList() {
                var that = this;
                var apiUrlData = {
                    1: {
                        url: Config.api.TransferGtListByPayee,
                        data: {
                            payee_user_id: that.userInfo.user_id,
                            pages: that.listPage
                        }
                    },
                    2: {
                        url: Config.api.TransferGetListByDrawee,
                        data: {
                            drawee_user_id: that.userInfo.user_id,
                            pages: that.listPage
                        }
                    }
                };
                _ajax(apiUrlData[that.listType].url, apiUrlData[that.listType].data, function(ret) {
                    if (ret.code === 200) {
                        if (that.listPage === 1) {
                            that.list = ret.data;
                        } else {
                            if (ret.data.length > 0) {
                                that.list = that.list.concat(ret.data);
                            } else {
                                that.listStatus = false;
                            }
                        }
                    }
                });
            },
            cannel(o) {
                var name = "cannel_pay_win";
                var url = "./cannel_pay_win.html";
                open_w(name, url, o);
            },
            goPay(o) {
                var name = "pay_order_win";
                var url = "./pay_order_win.html";
                open_w(name, url, o);
            },
            tabChange() {
                var that = this;
                var tab = new auiTab({
                    element: document.getElementById("tab"),
                    index: 1,
                    repeatClick: false
                }, function(ret) {
                    that.listType = ret.index;
                    that.listPage = 1;
                    that.listStatus = true;
                    that.getList();
                });
            },
            upDownLoad() {
                var that = this;

                // 下拉刷新
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();
                    that.listStatus = true;
                    that.listPage = 1;
                    that.list = [];
                    that.getList();
                });

                //上拉加载
                push_up(function() {
                    if (that.listStatus) {
                        that.listPage++;
                        that.getList();
                    }
                });
            },
        }
    });
</script>

</html>
